// 指纹报告模板配置
import { axios } from "@/plugins/axios";
import merge from "lodash/merge";
import { User } from "./user";
import { FileStore } from "./file";

const ReportTargets = ["职场分析", "学龄教育"];

const LearnTraitEnum = ["认知型", "开放型", "模仿型", "逆思型", "反射型"];

class LearnTraitConfig {
  // 先天学习特质
  constructor() {
    this.id = 0;
    this.report_target = "学龄教育";
    this.learn_trait = "认知型";
    this.content = "";
    this.content_text = "";
    this.audio = null
    this.created_by = new User();
    this.updated_by = new User();
    this.update_time = new Date();
    this.create_time = new Date();
  }

  static fetch(query_args = {}, page = 1, per_page = 10) {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/learn_trait";
    let params = { ...query_args, per_page: per_page, page: page };

    return axios.get(url, { params: params }).then((res) => {
      let results = [];
      res.data.results.forEach((item) => {
        const data = merge(new LearnTraitConfig(), item);
        results.push(data);
      });
      return { total: res.data.total, pages: res.data.pages, results: results };
    });
  }

  static async getById(id) {
    const res = await this.fetch({ id: id }, 1, 0);
    if (res.total > 0) {
      return res.results[0];
    } else {
      return null;
    }
  }

  createOrUpdate() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/learn_trait";
    const data = Object.assign({}, this);

    if (!data.id || data.id == 0) {
      delete data.id;
    }
    return axios.post(url, data).then((res) => {
      const data = merge(new LearnTraitConfig(), res.data.data);
      return data;
    });
  }
  delete() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/learn_trait";
    const params = { id: this.id };
    return axios.delete(url, { params: params }).then((res) => {
      return true;
    });
  }
}

const LearnTypeEnum = ["动机型", "构思型", "体觉型", "听觉型", "视觉型"];
class LearnTypeConfig {
  // 先天学习类型
  constructor() {
    this.id = 0;
    this.report_target = "学龄教育";
    this.learn_type = "动机型";
    this.content = "";
    this.content_text = "";
    this.audio = null
    this.created_by = new User();
    this.updated_by = new User();
    this.update_time = new Date();
    this.create_time = new Date();
  }

  static fetch(query_args = {}, page = 1, per_page = 10) {
    const url = process.env.VUE_APP_API_URL + "api/v1/finger_config/learn_type";
    let params = { ...query_args, per_page: per_page, page: page };

    return axios.get(url, { params: params }).then((res) => {
      let results = [];
      res.data.results.forEach((item) => {
        const data = merge(new LearnTypeConfig(), item);
        results.push(data);
      });
      return { total: res.data.total, pages: res.data.pages, results: results };
    });
  }

  static async getById(id) {
    const res = await this.fetch({ id: id }, 1, 0);
    if (res.total > 0) {
      return res.results[0];
    } else {
      return null;
    }
  }

  createOrUpdate() {
    const url = process.env.VUE_APP_API_URL + "api/v1/finger_config/learn_type";
    const data = Object.assign({}, this);

    if (!data.id || data.id == 0) {
      delete data.id;
    }
    return axios.post(url, data).then((res) => {
      const data = merge(new LearnTypeConfig(), res.data.data);
      return data;
    });
  }
  delete() {
    const url = process.env.VUE_APP_API_URL + "api/v1/finger_config/learn_type";
    const params = { id: this.id };
    return axios.delete(url, { params: params }).then((res) => {
      return true;
    });
  }
}

const NaturalPropertyEnum = ["鲜花", "白云", "高山", "大树", "流水"];
class NaturalPropertyConfig {
  // 自然属性
  constructor() {
    this.id = 0;
    this.report_target = "学龄教育";
    this.natural_property = "鲜花";
    this.content = "";
    this.content_text = "";
    this.audio = null
    this.created_by = new User();
    this.updated_by = new User();
    this.update_time = new Date();
    this.create_time = new Date();
  }

  static fetch(query_args = {}, page = 1, per_page = 10) {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/natural_property";
    let params = { ...query_args, per_page: per_page, page: page };

    return axios.get(url, { params: params }).then((res) => {
      let results = [];
      res.data.results.forEach((item) => {
        const data = merge(new NaturalPropertyConfig(), item);
        results.push(data);
      });
      return { total: res.data.total, pages: res.data.pages, results: results };
    });
  }

  static async getById(id) {
    const res = await this.fetch({ id: id }, 1, 0);
    if (res.total > 0) {
      return res.results[0];
    } else {
      return null;
    }
  }

  createOrUpdate() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/natural_property";
    const data = Object.assign({}, this);

    if (!data.id || data.id == 0) {
      delete data.id;
    }
    return axios.post(url, data).then((res) => {
      const data = merge(new NaturalPropertyConfig(), res.data.data);
      return data;
    });
  }
  delete() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/natural_property";
    const params = { id: this.id };
    return axios.delete(url, { params: params }).then((res) => {
      return true;
    });
  }
}

const OmniIntelligenceEnum = [
  "人际智能",
  "内省智能",
  "语言智能",
  "音乐智能",
  "空间智能",
  "数学逻辑",
  "大肢体运动",
  "小肢体运动",
  "自然观察图形",
  "自然观察视觉",
];

class OmniIntelligenceConfig {
  // 多元智能
  constructor() {
    this.id = 0;
    this.report_target = "学龄教育";
    this.intelligence_type = "人际智能";
    this.content = "";
    this.content_text = "";
    this.audio = null
    this.created_by = new User();
    this.updated_by = new User();
    this.update_time = new Date();
    this.create_time = new Date();
  }

  static fetch(query_args = {}, page = 1, per_page = 10) {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/omni_itelligence";
    let params = { ...query_args, per_page: per_page, page: page };

    return axios.get(url, { params: params }).then((res) => {
      let results = [];
      res.data.results.forEach((item) => {
        const data = merge(new OmniIntelligenceConfig(), item);
        results.push(data);
      });
      return { total: res.data.total, pages: res.data.pages, results: results };
    });
  }

  static async getById(id) {
    const res = await this.fetch({ id: id }, 1, 0);
    if (res.total > 0) {
      return res.results[0];
    } else {
      return null;
    }
  }

  createOrUpdate() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/omni_itelligence";
    const data = Object.assign({}, this);

    if (!data.id || data.id == 0) {
      delete data.id;
    }
    return axios.post(url, data).then((res) => {
      const data = merge(new OmniIntelligenceConfig(), res.data.data);
      return data;
    });
  }
  delete() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/omni_itelligence";
    const params = { id: this.id };
    return axios.delete(url, { params: params }).then((res) => {
      return true;
    });
  }
}

const HandSideEnum = [
  { name: "左手", value: "left" },
  { name: "右手", value: "right" },
];

const FingerIndexEnum = [ "拇指", "食指", "中指", "无名指", "小指"];

const FingerClassifyEnum = ["斗纹", "双斗", "正箕纹", "反箕纹", "弧纹"]

class ClassifyAnalyseConfig {
  // 纹路解析
  constructor() {
    this.id = 0;
    this.report_target = "学龄教育";
    this.is_intro = false
    this.handside = "left";
    this.finger_index = "拇指"
    this.finger_zh_class = "斗纹";
    this.content = "";
    this.content_text = "";
    this.audio = null
    this.created_by = new User();
    this.updated_by = new User();
    this.update_time = new Date();
    this.create_time = new Date();
  }

  static fetch(query_args = {}, page = 1, per_page = 10) {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/classify_analyse";
    let params = { ...query_args, per_page: per_page, page: page };

    return axios.get(url, { params: params }).then((res) => {
      let results = [];
      res.data.results.forEach((item) => {
        const data = merge(new ClassifyAnalyseConfig(), item);
        results.push(data);
      });
      return { total: res.data.total, pages: res.data.pages, results: results };
    });
  }

  static async getById(id) {
    const res = await this.fetch({ id: id }, 1, 0);
    if (res.total > 0) {
      return res.results[0];
    } else {
      return null;
    }
  }

  createOrUpdate() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/classify_analyse";
    const data = Object.assign({}, this);

    if (!data.id || data.id == 0) {
      delete data.id;
    }
    return axios.post(url, data).then((res) => {
      const data = merge(new ClassifyAnalyseConfig(), res.data.data);
      return data;
    });
  }
  delete() {
    const url =
      process.env.VUE_APP_API_URL + "api/v1/finger_config/classify_analyse";
    const params = { id: this.id };
    return axios.delete(url, { params: params }).then((res) => {
      return true;
    });
  }
}


class SimpleFingerReportConfig {
  // 简单版报告配置
  constructor() {
    this.id = 0
    this.handside = "left"
    this.finger_index = "拇指"
    this.finger_zh_class = "斗纹"
    this.content = ""
    this.created_by = new User()
    this.updated_by = new User()
    this.update_time = new Date()
    this.create_time = new Date()
  }

  static fetch(query_args = {}, page = 1, per_page = 10) {
    const url = process.env.VUE_APP_API_URL + "api/v1/finger_config/simple"
    let params = { ...query_args, per_page: per_page, page: page }

    return axios.get(url, { params: params }).then((res) => {
      let results = []
      res.data.results.forEach((item) => {
        const data = merge(new SimpleFingerReportConfig(), item)
        results.push(data)
      })
      return { total: res.data.total, pages: res.data.pages, results: results }
    })
  }

  static async getById(id) {
    const res = await this.fetch({ id: id }, 1, 0)
    if (res.total > 0) {
      return res.results[0]
    } else {
      return null
    }
  }

  createOrUpdate() {
    const url = process.env.VUE_APP_API_URL + "api/v1/finger_config/simple"
    const data = Object.assign({}, this)

    if (!data.id || data.id == 0) {
      delete data.id
    }
    return axios.post(url, data).then((res) => {
      const data = merge(new SimpleFingerReportConfig(), res.data.data)
      return data
    })
  }
  delete() {
    const url = process.env.VUE_APP_API_URL + "api/v1/finger_config/simple"
    const params = { id: this.id }
    return axios.delete(url, { params: params }).then((res) => {
      return true
    })
  }
}


export {
  ReportTargets,
  LearnTraitEnum,
  LearnTraitConfig,
  LearnTypeEnum,
  LearnTypeConfig,
  NaturalPropertyEnum,
  NaturalPropertyConfig,
  OmniIntelligenceEnum,
  OmniIntelligenceConfig,
  HandSideEnum,
  FingerIndexEnum,
  FingerClassifyEnum,
  ClassifyAnalyseConfig,
  SimpleFingerReportConfig
};
